package org.rcloud.io.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.ApiOperation;
import org.rcloud.io.Utils.ResultVo;
import org.rcloud.io.model.PathWay;
import org.rcloud.io.service.PathWayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;


import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import java.util.UUID;

/**
 * Created by Administrator on 2019/3/7.
 */
@RestController
@RequestMapping(value = "/PathWay")
public class PathWayController {

    @Autowired
    private PathWayService pathWayService;

   /*
    * 保存轨道采集信息
    * */
    @ApiOperation(value="保存轨道采集信息", notes="保存轨道采集信息")
    @ResponseBody
    @RequestMapping(value = "/save", produces = {"application/json;charset=UTF-8"})
    public ResultVo savePathWay(@RequestBody String params){

        JSONObject object =JSON.parseObject(params);

        Map map = JSON.parseObject(object.toString());
        String id = UUID.randomUUID().toString() ;
        String linenum = map.get("linenum").toString();
        String linename = map.get("linename").toString();
        String linesummary = map.get("linesummary").toString();
        String linetype = map.get("linetype").toString();
        String linepoly = map.get("linepoly").toString();
        String report = map.get("report").toString();
        String reportphone = map.get("reportphone").toString();

        Date t = new Date();
        Timestamp createData = new Timestamp(t.getTime());

        PathWay pathWay = new PathWay();
        pathWay.setId(id);
        pathWay.setLinenum(linenum);
        pathWay.setLinename(linename);
        pathWay.setLinesummary(linesummary);
        pathWay.setLinetype(linetype);
        pathWay.setLinepoly(linepoly);
        pathWay.setReport(report);
        pathWay.setReportphone(reportphone);
        pathWay.setCreatedata(createData);
        pathWay.setFlag(1);

        return pathWayService.save(pathWay);
    }

}
